package cn.yr.oauth.configuration;

import cn.yr.oauth.properties.AlipayProperties;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthAlipayRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 未写该配置oauth.alipay.clientId时不会加载AlipayConfiguration
 */
/**
 * @author lang 1102076808@qq.com
 * @description
 * @date 21:21d 2021/5/1
 **/
@Configuration
@EnableConfigurationProperties(AlipayProperties.class)
@ConditionalOnProperty(
        prefix = "oauth.alipay",
        name = "clientId"
)

public class AlipayConfiguration {

    @Autowired
    private AlipayProperties alipayProperties;

    @Bean
    public AuthAlipayRequest getAuthAlipayRequest(){
        return new AuthAlipayRequest(AuthConfig.builder()
                .clientId(alipayProperties.getClientId())
                .clientSecret(alipayProperties.getClientSecret())
                .alipayPublicKey(alipayProperties.getAlipayPublicKey())
                .redirectUri(alipayProperties.getRedirectUrl())
                .build());
    }

}
